import 'dart:math' as math show atan, pi;

class MathUtil {
  /// 获取两条线的夹角
  static double getLinesAngle(
      double centerX, double centerY, double xInView, double yInView) {
    double rotation = 0;
    double k1 = (centerY - centerY) / (centerX * 2 - centerX);
    double k2 = (yInView - centerY) / (xInView - centerX);
    double tmpDegree =
        math.atan(((k1 - k2).abs()) / (1 + k1 * k2)) / math.pi * 180;

    if (xInView > centerX && yInView < centerY) {
      //第一象限(数学意义上的)
//            rotation = 90 - tmpDegree;
      rotation = 360 - tmpDegree;
    } else if (xInView > centerX && yInView > centerY) {
      //第四象限
//            rotation = 90 + tmpDegree;
      rotation = tmpDegree;
    } else if (xInView < centerX && yInView > centerY) {
      //第三象限
      rotation = 180 - tmpDegree;
//            rotation = 270 - tmpDegree;

    } else if (xInView < centerX && yInView < centerY) {
      //第二象限
      rotation = 180 + tmpDegree;
//            rotation = 270 + tmpDegree;
    } else if (xInView == centerX && yInView < centerY) {
//            rotation = 0;
      rotation = 270;
    } else if (xInView == centerX && yInView > centerY) {
//            rotation = 180;
      rotation = 90;
    } else if (xInView < centerX && yInView == centerY) {
//            rotation = 0;
      rotation = 180;
    } else if (xInView > centerX && yInView == centerY) {
//            rotation = 180;
      rotation = 0;
    }

    return rotation;
  }
}
